<%@ page contentType="text/html;charset=UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="static/element/index.css">
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title></title>
    <style>
        .fail .layui-layer-content {
            background-color: brown;
            color: #eee;
            width: 400px;
            height: 30px;
            text-align: center;
        }

        .succeed .layui-layer-content {
            background-color: #0061A8;
            color: #eee;
            width: 400px;
            height: 30px;
            text-align: center;
        }

        * {
            padding: 0;
            margin: 0;
        }

        html {
            overflow-y: hidden;
        }

        body, html {
            width: 100%;
            height: 100%;
        }

        body {
            display: flex;
            flex-flow: column;
        }

        .fheader {
            height: 1%;
            min-height: 50px;
        }

        .fsection {
            /*flex-grow: 1;*/
            display: flex;
            flex-flow: row;
            margin-top: 10px;
            /*height: 99%;*/
            min-height: 0;
        }

        .farticle {
            flex: 1;
            padding: 1px;
        }

        .el-table__body tr:hover > td {
            background-color: #DFDFDF !important;
            cursor: default
        }

    </style>
</head>
<body>
<div id="app">
    <div class="fheader" style="padding: 0;margin: 0 ">
        <nav class="breadcrumb" style="height: 100%; padding: 0;margin-top: 8px ">

            <el-row>
                <div class="l" style="margin-top: 5px; margin-left: 20px; ">
                    <el-date-picker
                            v-model="value2"
                            type="datetimerange"
                            :picker-options="pickerOptions"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            format="yyyy-MM-dd HH:mm"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            align="right">
                    </el-date-picker>
                </div>
                <a class="btn btn-success radius" style="line-height:1.6em; margin-left: 8px; margin-top: 10px;" @click="fBegin()" title="查询" v-loading.fullscreen.lock="fullscreenLoading">查询</a>
                <span class="r">
                    <a style="margin-top: 10px" @click="fDown()" class="btn .btn-secondary radius">下一页</a>
                </span>
                <span class="r">
                    <a style="margin-top: 10px" @click="fUp()" class="btn .btn-secondary radius">上一页</a>
                </span>
                <span class="r" style="padding-top: 6px;">共有数据：[<strong>{{iiCount}}</strong> 条]</span>
            </el-row>
        </nav>
    </div>

    <div class="fsection">
        <div class="farticle">
            <div style="height: 100%; width: 100%; overflow: scroll; float: left; overflow-x: hidden;">
                <el-table :data="tableData" stripe border style="width: 100%" :height="tableHeightL" empty-text="没有数据" :header-cell-style="tableHeaderCellStyleL" :cell-style="tableCellStyleL">
                    <el-table-column prop="VALUE01" label="序号" width="90"></el-table-column>
                    <el-table-column prop="VALUE02" label="内容"></el-table-column>
                    <el-table-column prop="VALUE03" label="操作员" width="110"></el-table-column>
                    <el-table-column prop="VALUE04" label="日期" width="150"></el-table-column>
                </el-table>
            </div>
        </div>
    </div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/Layui_30023/layui.all.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/layui_exts/excel.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="static/axios.min.js"></script>
<script type="text/javascript" src="./static/vue"></script>
<script src="static/element/index.js"></script>
<script type="text/javascript">
    let vm = new Vue({
        el: '#app',
        data: {
            ryzh: '',
            state2: '',
            restaurants: [],
            pickerOptions: {
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        const end = new Date(new Date().setHours(23, 59, 59))
                        const start = new Date(new Date().setHours(0, 0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const end = new Date(new Date(new Date().getTime() - 24 * 60 * 60 * 1000).setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 24 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '前天',
                    onClick(picker) {
                        const end = new Date(new Date(new Date().getTime() - 48 * 60 * 60 * 1000).setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 48 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近7天',
                    onClick(picker) {
                        const end = new Date(new Date().setHours(23, 59, 59))
                        const start = new Date(new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000).setHours(0, 0, 0))
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '本月',
                    onClick(picker) {
                        let date = new Date();
                        let year = date.getFullYear()
                        let month = parseInt(date.getMonth());
                        const start = new Date(year, month, 1, 0, 0, 0);
                        const end = new Date(new Date().setHours(23, 59, 59))
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            value2: [],

            dateBb: '',
            dateEe: '',
            ii_page: 1,   //--上一页下一页的计数器
            ii_row: 20,   //--每页显示的记录数
            iiCount: 0,
            tableData: [],      //--具体人员信息表
            fullscreenLoading: false
        },
        methods: {
            fReset() {
                this.value2 = ''
                this.state2 = ''
                this.ii_page = 1   //--上一页下一页的计数器
                this.iiCount = 0
                this.tableData = []      //--具体人员信息表
            },

            fUp() {
                if (this.ii_page > 1) {
                    this.ii_page--;
                    this.fGetinfo()
                } else {
                    layer.msg('<span style="font-size:24px; line-height: 30px">已是第一页!</span>', {time: 2000, skin: 'fail'});
                }
            },

            fDown() {
                if (this.ii_page * 20 < this.iiCount) {
                    this.ii_page++;
                    this.fGetinfo()
                } else {
                    layer.msg('<span style="font-size:24px; line-height: 30px">已是最后一页!</span>', {time: 2000, skin: 'fail'});
                }
            },

            fBegin() {
                this.ii_page = 1
                this.fGetinfo()
            },

            fGetinfo() {
                if (this.value2.length === 0) {
                    layer.msg('<span style="font-size:24px; line-height: 30px">请选择查询的起止时间!</span>', {time: 2000, skin: 'fail'});
                    return
                }

                this.dateBb = this.dateFormat(this.value2[0])
                this.dateEe = this.dateFormat(this.value2[1])

                this.fullscreenLoading = true
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "ZI");
                params.append('VALUE01', ((this.ii_page - 1) * parseInt(this.ii_row)).toString());
                params.append('VALUE02', ((this.ii_page) * this.ii_row).toString());
                params.append('VALUE03', this.dateBb);
                params.append('VALUE04', this.dateEe);
                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        let {db1, db2} = res.data
                        if (db1.length === 0) {
                            layer.msg('<span style="font-size:26px; line-height: 30px">没有相关记录</span>', {time: 2000, skin: 'fail'});
                        } else {
                            if (db1[0].VALUE01 === 'ZZ01') {
                                layer.msg('<span style="font-size:26px; line-height: 30px">' + db1[0].VALUE02 + '</span>', {time: 2000, skin: 'fail'});
                            } else {
                                self.tableData = db1
                                self.iiCount = db2[0].VALUE01
                            }
                        }
                    })
                    .catch(function (error) {
                        layer.msg('<span style="font-size:24px; line-height: 30px">网络异常错误!</span>', {time: 2000, skin: 'fail'});
                    }).finally(function () {
                    self.fullscreenLoading = false
                });

            },

            tableHeaderCellStyleL({row, column, rowIndex, columnIndex}) {
                let cellStyle1;

                cellStyle1 = "color: #fff;" +
                    "background:#4F4F4F;" +
                    "text-align:center;" +
                    "font-size:12px"

                return cellStyle1
            },

            tableCellStyleL({row, column, rowIndex, columnIndex}) {
                let cellStyle1;

                if (columnIndex === 1) {
                    cellStyle1 = "text-align:left;" +
                        "padding:8px 1px 8px;" +
                        "font-size:12px"
                } else {
                    cellStyle1 = "text-align:center;" +
                        "padding:8px 1px 8px;" +
                        "font-size:12px"
                }
                return cellStyle1;
            },

            querySearch(queryString, cb) {
                let restaurants = this.restaurants;
                let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },

            createFilter(queryString) {
                return (restaurants) => {
                    return (restaurants.value.toLowerCase().indexOf(queryString.toLowerCase()) >= 0);
                };
            },

            //--输入框选择后的人员帐号
            handleSelect(item) {
                this.ryzh = item.address
            },

            dateFormat: function (time) {
                const date = new Date(time);
                const year = date.getFullYear();
                /* 在日期格式中，月份是从0开始的，因此要加0
                 * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
                 * */
                const month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                const hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
                const minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
                const seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
                // 拼接
                return year + "-" + month + "-" + day + ' ' + hours + ':' + minutes + ':' + seconds;
            },

            //--核销
            fKk(title, obj) {
                let self = this
                layer.confirm("确定对注销信息核销？", {
                    btn: ["确定", "取消"] //按钮
                }, function () {
                    if (!this.lock) {
                        this.lock = true
                        let params = new URLSearchParams();
                        params.append('CMD', "BT");
                        params.append('VALUE01', obj.VALUE10);
                        axios.post('/f_wscl/com2', params)
                            .then(function (res) {
                                let {db1} = res.data
                                if (db1[0].VALUE01 === 'ZZ01') {
                                    layer.msg('<span style="font-size:26px; line-height: 30px">' + db1[0].VALUE02 + '</span>', {time: 2000, skin: 'fail'});
                                } else if (db1[0].VALUE01 === 'ZZ00') {
                                    layer.msg("<span style='font-size:26px; line-height: 30px'>核销完毕!</span>", {time: 2000, skin: 'succeed'}, function () {
                                        let index = parent.layer.getFrameIndex(window.name);
                                        self.fGetinfo()
                                        parent.layer.close(index);
                                    });
                                }
                            })
                            .catch(function (error) {
                                layer.msg('<span style="font-size:26px; line-height: 30px">网络异常错误!</span>', {time: 1500, skin: 'fail'});
                            })
                            .finally(function () {
                                self.lock = false
                            });
                    }
                    //--如下两个备注留着，用来确定是否关闭弹出的界面而不关闭显示流水的列表界面
                    // layer.closeAll('dialog');
                    // layer.close(index);
                }, function () {
                });
            },

            fInit() {
                let self = this
                let params = new URLSearchParams();
                params.append('CMD', "BR");

                axios.post('/f_wscl/com2', params)
                    .then(function (res) {
                        let {db1} = res.data
                        self.restaurants = JSON.parse(JSON.stringify(db1).replace(/VALUE01/g, "value").replace(/VALUE02/g, "address"));
                    })
                    .catch(function (error) {
                        layer.msg('<span style="font-size:24px; line-height: 30px">网络异常错误!</span>', {time: 2000, skin: 'fail'});
                    });
            },
        },
        mounted() {
            this.fInit()
        },

        created() {
            let windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
            this.tableHeightL = windowHeight - 85;

            //当前设定的日期时间
            let d = new Date
            let year1, month1, day1, h1, f1, m1;
            [year1, month1, day1, h1, f1, m1] = [d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds()]
            let date1 = new Date(year1, month1, day1, 23, 59, 59)
            this.value2.push(date1)
            // //前一天设定的日期时间
            let year2, month2, day2
            d.setTime(d.getTime() - 60 * 60 * 1000);
            [year2, month2, day2] = [d.getFullYear(), d.getMonth(), d.getDate()]
            let date2 = new Date(year2, month2, day2, 0, 0, 0)
            this.value2.unshift(date2)
        }
    });

</script>

</body>
</html>
